package com.dragonlance;

import org.apache.mina.core.session.IoSession;

import com.dragonlance.beans.User;
import com.dragonlance.net.PackageOut;
import com.dragonlance.net.out.ClientOut;
import com.dragonlance.scene.item.Player;

public class DLClient {
	private IoSession session;
	private User user;
	private Player player;
	public ClientOut out;
	
	public DLClient(IoSession session, User user) {
		this.session = session;
		this.user = user;
		this.player = new Player(this);
		out = new ClientOut(this,session);
	}
	
	public long getId(){
		return session.getId();
	}
	
	public long getUserId(){
		return user.getUid();
	}
	
	public User getUser(){
		return user;
	}
	
	public Player getPlayer(){
		return player;
	}
	
	public void send(PackageOut pkg){
		this.session.write(pkg);
	}
	
	public void disconnect(){
		session.close(true);
		exit();
	}

	public void exit() {
		System.out.println("Client Exit");
		user.save();
	}
}
